#include "../source/server.hpp"

int main()
{
    Socket cli_sock;
    if (!cli_sock.CreateClient(8800, "127.0.0.1")) {
        ELOG("连接服务器失败");
        return -1;
    }
    DLOG("连接服务器成功");
    for (int i = 0; i < 5; i++)
    {
        std::string buff = "hello";
        ssize_t sret = cli_sock.Send(buff.c_str(), buff.size());
        if (sret < 0) {
            std::cout << "发送失败" << std::endl;
            break;
        }
        //DLOG("发送成功");
        char buf[1024] = {0};
        ssize_t rret = cli_sock.Recv(buf, 1023);
        if (rret <= 0) {
            std::cout << "接收失败或对端关闭" << std::endl;
            break;
        }
        //std::cout << buf << std::endl;
        std::cout << "收到响应: " << buf << std::endl;
        sleep(1);
    }
    while(1){sleep(1);}
    cli_sock.Close();
    DLOG("Client closed");
    return 0;
}